<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1">
	    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
	    <title>Bootstrap 101 Template</title>
	    <!-- Bootstrap -->
	    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
	    <link rel="stylesheet" type="text/css" href="css/Shop.css"/>
	</head>
	<body>
		<div class="Shop_title">
         	菜品类型
         </div>
		<table class="table table-hover">
			<tr>
     			<th width="10%">菜品序号</th>
     			<th>菜品类型名称</th>
     			<th width="20%">操作</th>
     		</tr>
		</table>
	</body>
	<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
	<script>	
		$(document).ready(function(){
			$.ajax({
			   type: "POST",
			   url: "http://befull.mcaa.win/foodTypeSelectByshopid.action",
			   data: "shopid=2",
			   dataType: "jsonp",
			   jsonp: "callback",
			   success: function(msg){
			    var data = msg.data;
			    for(var i=0;i<data.length;i++){
			    	var addtr = "<tr><td>"+data[i].foodTypeId+"</td><td>"+data[i].foodTypeName+"</td><td><button id='XG' onclick='XG()'>修改</button><button onclick='SH(this)'>删除</button></td></tr>"
			    	$("table").append(addtr);
			    }
			   },
			   error:function(){
			   		console.log("请求超时错误");
			   }
			});
		})
		function XG(){
			window.location.href="updateFoodType.html";
		}
		function SH(e){
			var id = $(e).parent().parent().find("td").first().text();
			$.ajax({
			   type: "POST",
			   url: "http://befull.mcaa.win/foodTypeDelete.action",
			   data: "foodTypeId="+id,
			   dataType: "jsonp",
			   jsonp: "callback",
			   success: function(msg){
			   	var mesg = msg.data;
			   	alert(mesg);
			   },
			   error:function(){
			   		console.log("请求超时错误");
			   }
			});
			$("table").empty();
			$("table").append("<tr><th width='10%'>菜品序号</th><th>菜品类型名称</th><th width='20%'>操作</th></tr>");
			$.ajax({
			   type: "POST",
			   url: "http://befull.mcaa.win/foodTypeSelectByshopid.action",
			   data: "shopid=2",
			   dataType: "jsonp",
			   jsonp: "callback",
			   success: function(msg){
			    var data = msg.data;
			    for(var i=0;i<data.length;i++){
			    	var addtr = "<tr><td>"+data[i].foodTypeId+"</td><td>"+data[i].foodTypeName+"</td><td><button id='XG' onclick='XG()'>修改</button><button onclick='SH(this)'>删除</button></td></tr>"
			    	$("table").append(addtr);
			    }
			   },
			   error:function(){
			   		console.log("请求超时错误");
			   }
			});
		}
	</script>
</html>
